package com.qingfeng.core.dao.qingfeng;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qingfeng.core.config.database.BaseMapper;
import com.qingfeng.core.dao.BaseDao;
import com.qingfeng.core.entity.qingfeng.Task;
import com.qingfeng.core.mapper.qingfeng.TaskMapper;
import com.qingfeng.core.utils.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 任务
 * @author:LWY
 * @date: 2017/10/16 17:15
 * @modified:
 */

@Repository
public class TaskDao extends BaseDao<Task> {

    @Autowired
    TaskMapper taskMapper;

    @Override
    protected BaseMapper<Task> getBaseMapper() {
        return taskMapper;
    }


    /**
     * 发布任务
     *
     * @param task
     * @return
     */
    public Task release(Task task) {
        String id = UuidUtil.generatorUUID();
        task.setId(id);
        task.setState(1);
        task.setCreate_time(new Date());
        taskMapper.insertSelective(task);
        return task;
    }

    /**
     * 与我有关任务
     *
     * @param user_id 用户id
     * @param type    类型（1：我发布的任务、2:我的抢单）
     * @param state   任务状态（1:未发布状态，2：已经发布了）
     */
    public PageInfo<HashMap<String, Object>> my(Integer pageNum, Integer pageSize, String user_id, Integer type, Integer state) {
        if (pageNum == null || pageSize == null) {
            pageNum = 0;
            pageSize = 0;
        }
        PageHelper.startPage(pageNum, pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("user_id", user_id);
        map.put("type", type);
        map.put("state", state);
        List<HashMap<String, Object>> list = taskMapper.my(map);
        PageInfo<HashMap<String, Object>> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
